﻿<?php
header("Content-type: text/html; charset=utf-8");
if ($_GET['word'])
    $_GET['word'] = htmlspecialchars($_GET['word']);
if(isset($_GET['jkm']) && $_GET['jkm']){
    
    $_SESSION['df_sjh'] = $_GET['sjh'];
    $_SESSION['df_jkm'] = $_GET['jkm'];
}
if (isset($_SESSION['df_jkm']) && isset($_SESSION['df_sjh']) && $_GET['bjs'] != '1'){
    $result = $conn->query("SELECT * FROM hg002 WHERE sjh='" . $_SESSION['df_sjh'] . "'");
    if($row = mysqli_fetch_array($result)) {
        $sj = intval($row['wdsj']);
        $s_wd = $_GET['word'];
        if(time() - $sj <= 60 * 5){
            $s_wd .= '<br />'.$row['wd'];
        }
    }
    if ($conn->query("UPDATE hg002 SET wd='" . $s_wd . "',wdsj='".time()."' WHERE sjh='" . $_SESSION['df_sjh'] .
        "'")) {

    }
    $sql = "SELECT * FROM hg002_wd WHERE wd='".$_GET['word']."'";
    $result = $conn->query($sql);
    if($result)
        if($row = mysqli_fetch_array($result))
        {
            if ($conn->query("UPDATE hg002_wd SET count=" . ($row['count'] + 1) . " WHERE wd='".$_GET['word']."'")){
                
            }
        }else{
            $sql = "INSERT INTO hg002_wd (wd,count) VALUES ('".$_GET['word']."', 1);";
            if ($conn->query($sql)){
                
            }
        }
}

$url = 'http://m.baidu.com' . $_SERVER["REQUEST_URI"];
$url = str_replace('index2.php','',$url);
//$url = str_replace('index2.php','',$url);
//$url = str_replace('lab/s/','s/',$url);
//$ls_jkmlj = "../mm/sz/".$_SESSION['df_sjh']."/jkm.txt";
$word = $_GET['word'];

if(substr($_SESSION['df_jkm'],0,1) == 'd')$_GET['hgyzl'] = '3.14159';
$html = file_get_contents("js.htm");
$html = str_replace('彩虹', $word, $html);
if ($_GET['bjs'] != '1') {
    $html = str_replace('return;', '', $html);
    if($_GET['hgyzl'] != '3.14159')
        $html = str_replace('return ;', '', $html);
    if (isset($_SESSION['df_jkm']) && isset($_SESSION['df_sjh'])) {
        $yzd = 0;
        $result = $conn->query("SELECT * FROM hg002 WHERE jkm like '{$_SESSION['df_jkm']}%'");
        if ($result){
            while ($row = mysqli_fetch_array($result)) {
                $sj = intval($row['jkmsj']);
                if(time() - $sj <= 60 * 5){
                    $js = $row['js'];
                    if ($js > 2 && $js < 60 * 3) {
                        $js *= 1000;
                        $html = str_replace('8000', $js, $html);
                        $yzd = 1;
                        break;
                    }
                }
            }
        }
        if($yzd != 1){
            $Xjkm = $_SESSION['df_jkm'];
            if($_SESSION['df_jkm'] < 0)
                $Xjkm = -$Xjkm;
            $result = $conn->query("SELECT * FROM hg002 WHERE jkm like '%{$Xjkm}'");
            if ($result){
                while ($row = mysqli_fetch_array($result)) {
                    $sj = intval($row['jkmsj']);
                    if(time() - $sj <= 60 * 5){
                        $js = $row['js'];
                        if ($js > 2 && $js < 60 * 3) {
                            $js *= 1000;
                            $html = str_replace('8000', $js, $html);
                            break;
                        }
                    }
                }
            }
        }
        
    }
    
}
echo $html;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_exec($ch);
//释放curl句柄
curl_close($ch);
echo '<script>kaishizhixing();</script>';
?>